﻿using Godot;
using Godot.Collections;
using System;

public class SteamBoilerTankEntity : BlockEntity
{
    public int tick = 5;
    public FluidData fuel = new FluidData("fuel", 0, 0);
    public FluidData water = new FluidData("water", 0, 16000);
    public FluidData thermal = new FluidData("thermal", 0, 500);
    public FluidData steam = new FluidData("steam", 0, 16000);
    public Store store = new Store(8);

    public override Dictionary getDict()
    {
        Dictionary dict = new Dictionary();
        dict.Add("fuel", fuel.GetDictionary());
        dict.Add("store", store.getDict());
        dict.Add("water", water.GetDictionary());
        dict.Add("thermal", thermal.GetDictionary());
        dict.Add("steam", steam.GetDictionary());
        dict.Add("tick", tick);
        return dict;
    }
    public override BlockEntity JsonTo(Dictionary dict)
    {
        if (dict.Contains("store")) this.store.JsonTo((Dictionary)dict["store"]);
        thermal.Parse((Dictionary)dict["thermal"]);
        water.Parse((Dictionary)dict["water"]);
        steam.Parse((Dictionary)dict["steam"]);
        fuel.Parse((Dictionary)dict["fuel"]);
        tick = dict["tick"].ToInt();
        return this;
    }
    public override FluidData GetFluid(int index)
    {
        if (index == 0) return water;
        else if (index == 1) return thermal;
        else if (index == 2) return steam;
        else return null;
    }
    public override FluidData GetFluid(String name)
    {
        if (name == "water") return water;
        else if (name == "thermal") return thermal;
        else if (name == "steam") return steam;
        else return null;
    }
    public override String toJson()
    {
        return JSON.Print(getDict());
    }
    public override Store GetStore()
    {
        return store;
    }
}
